package light.head.dao.oa;


import java.util.ArrayList;

import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Service;
import light.head.constant.Parm;
import light.head.enm.RESULT;
import light.head.framework.base.BaseDAO;
import light.head.framework.entity.PageBean;
import light.head.model.Reward;


@Service
public class RewardDAO extends BaseDAO<Reward, Integer>{
	
	
	public RESULT findByMap(Map<String, String> map, PageBean pageBean) {
		StringBuffer hql = new StringBuffer("FROM Reward d WHERE 1 = 1");
		
		List<Object> list = null;
		if (map != null) {
			list = new ArrayList<Object>();
			String name = map.get(Parm.UN);						//员工姓名
			String rtype = map.get(Parm.RTYPE);						//奖励类型
			String oc = map.get(Parm.OC);
			if (isNotNull(name)) {
				hql.append(" AND d.uc in (SELECT u.code FROM UserInfo u WHERE u.realName LIKE ?)");
				list.add("%" + name + "%");
			}if (isNotNull(rtype)) {
				hql.append(" AND d.rtype = ?");
				list.add(Byte.parseByte(rtype));
			}if (isNotNull(oc)) {
				hql.append(" AND d.oc = ?");
				list.add(Integer.parseInt(oc));
			}
		}
		hql.append(" AND (d.deleted = null or d.deleted = 0)");
		hql.append(" ORDER BY d.code DESC");
		
		if (findToPageBean(hql.toString(), pageBean, list) == RESULT.SUCCESS)
			return RESULT.SUCCESS;
		return RESULT.ERROR;
	}
	
}
